#include <bits/stdc++.h>

using namespace std;

int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
int current_count = 0;

void dfs(vector<vector<int>> &graph, vector<vector<bool>> &visited, int row, int col, int mark)
{
    if (graph[row][col] == 0 || visited[row][col] == true)
    {
        return;
    }
    graph[row][col] = mark;
    visited[row][col] = true;
    current_count++;
    for (int i = 0; i < 4; i++)
    {
        int next_row = row + dir[i][0];
        int next_col = col + dir[i][1];
        if (next_row < 0 || next_row >= (int)graph.size() || next_col < 0 || next_col >= (int)graph[0].size())
        {
            continue;
        }
        dfs(graph, visited, next_row, next_col, mark);
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n, vector<int>(m, 0));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> graph[i][j];
        }
    }

    bool is_all_island = true;
    vector<vector<bool>> visited(n, vector<bool>(m, false));
    int mark = 2;
    unordered_map<int, int> island_area;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            current_count = 0;
            if (graph[i][j] == 0)
            {
                is_all_island = false;
            }
            if (graph[i][j] == 1 && visited[i][j] == false)
            {
                dfs(graph, visited, i, j, mark);
            }
            island_area[mark] = current_count;
            mark++;
        }
    }

    if (is_all_island)
    {
        cout << n * m << endl;
        return 0;
    }

    int result = 0;
    int area = 1;
    unordered_set<int> set;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (graph[i][j] == 0)
            {
                set.clear();
                area = 1;
                for (int k = 0; k < 4; k++)
                {
                    int row = i + dir[k][0];
                    int col = j + dir[k][1];
                    if (row < 0 || row >= n || col < 0 || col >= m)
                    {
                        continue;
                    }
                    if (set.count(graph[row][col]))
                    {
                        continue;
                    }
                    if (island_area.count(graph[row][col]))
                    {
                        area += island_area[graph[row][col]];
                        set.insert(graph[row][col]);
                    }
                }
                result = max(result, area);
            }
        }
    }
    cout << result << endl;
    return 0;
}